package io.gitee.zhangbinhub.admin.oauth.controller.openinner

import io.gitee.zhangbinhub.acp.boot.exceptions.WebException
import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.admin.common.api.CommonPath
import io.gitee.zhangbinhub.admin.common.api.OauthApi
import io.gitee.zhangbinhub.admin.oauth.service.RoleService
import io.gitee.zhangbinhub.admin.resource.server.base.BaseResourceServerController
import io.gitee.zhangbinhub.admin.resource.server.vo.RoleVo
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Validated
@RestController
@RequestMapping(CommonPath.openInnerBasePath)
@Tag(name = "角色信息（内部开放接口）")
class OpenInnerRoleController @Autowired
constructor(
    logAdapter: LogAdapter,
    private val roleService: RoleService
) : BaseResourceServerController(logAdapter) {
    @Operation(summary = "获取角色详细信息")
    @GetMapping(value = [OauthApi.roleConfig + "/{roleId}"], produces = [MediaType.APPLICATION_JSON_VALUE])
    @Throws(WebException::class)
    fun roleInfo(@PathVariable(name = "roleId") roleId: String): ResponseEntity<RoleVo> =
        ResponseEntity.ok(roleService.getRoleInfo(roleId))

    @Operation(summary = "获取角色列表", description = "查询所有角色列表")
    @GetMapping(value = [OauthApi.roleConfig], produces = [MediaType.APPLICATION_JSON_VALUE])
    @Throws(WebException::class)
    fun roleList(): ResponseEntity<List<RoleVo>> = ResponseEntity.ok(roleService.getRoleVoList())
}